﻿using Common.Class;
using Common.Model;

namespace RdpClient.Forms
{
    public partial class FrmSessionRdp : Form
    {
        public SessionModel Session = new SessionModel(SessionType.SessionRdpClient);

        public FrmSessionRdp()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
            this.FormBorderStyle = FormBorderStyle.FixedDialog;//设置边框为不可调节
            this.MaximizeBox = false; //取消最大化按键
            this.MinimizeBox = false; //取消最小化按键
            this.ShowInTaskbar = false;//不在任务栏显示多个窗体框
        }

        private void FrmSessionRdp_Load(object sender, EventArgs e)
        {

            RdpSessionModel RdpSession = JsonHelper.GetObjectFromJsonStr<RdpSessionModel>(JsonHelper.GetJsonStrFromObject(Session.Data));
            if (RdpSession == null)
            {
                RdpSession = new RdpSessionModel();
            }
            txtName.Text = Session.Name;
            txtServer.Text = RdpSession.Server;
            txtPort.Text = RdpSession.Port.ToString();
            txtUserName.Text = RdpSession.UserName;
            txtPassword.Text = RdpSession.Password;
            txtDescription.Text = RdpSession.Description;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult
                .Cancel;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {

            RdpSessionModel RdpSession = new RdpSessionModel();
            Session.Data = RdpSession;
            Session.Name = txtName.Text.Trim();
            RdpSession.Server = this.txtServer.Text.Trim();
            RdpSession.Port = Convert.ToInt32(txtPort.Text.Trim());
            RdpSession.UserName = txtUserName.Text.Trim();
            RdpSession.Password = txtPassword.Text.Trim();
            RdpSession.IsShareDisk = chBoxIsShareDisk.Checked ? "Y" : "N";
            RdpSession.Description = txtDescription.Text.Trim();
            this.DialogResult = DialogResult.OK;
        }


    }
}
